package com.tledu.course.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.tledu.course.domain.ProjectManagement;
import com.tledu.course.service.IProjectManagementService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 专题管理Controller
 * 
 * @author Ghost
 * @date 2021-07-13
 */
@Controller
@RequestMapping("/course/project")
public class ProjectManagementController extends BaseController
{
    private String prefix = "course/project";

    @Autowired
    private IProjectManagementService projectManagementService;

    @RequiresPermissions("course:project:view")
    @GetMapping()
    public String project()
    {
        return prefix + "/project";
    }

    /**
     * 查询专题管理列表
     */
    @RequiresPermissions("course:project:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ProjectManagement projectManagement)
    {
        startPage();
        List<ProjectManagement> list = projectManagementService.selectProjectManagementList(projectManagement);
        return getDataTable(list);
    }

    /**
     * 导出专题管理列表
     */
    @RequiresPermissions("course:project:export")
    @Log(title = "专题管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProjectManagement projectManagement)
    {
        List<ProjectManagement> list = projectManagementService.selectProjectManagementList(projectManagement);
        ExcelUtil<ProjectManagement> util = new ExcelUtil<ProjectManagement>(ProjectManagement.class);
        return util.exportExcel(list, "专题管理数据");
    }

    /**
     * 新增专题管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存专题管理
     */
    @RequiresPermissions("course:project:add")
    @Log(title = "专题管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ProjectManagement projectManagement)
    {
        return toAjax(projectManagementService.insertProjectManagement(projectManagement));
    }

    /**
     * 修改专题管理
     */
    @GetMapping("/edit/{projectId}")
    public String edit(@PathVariable("projectId") Integer projectId, ModelMap mmap)
    {
        ProjectManagement projectManagement = projectManagementService.selectProjectManagementById(projectId);
        mmap.put("projectManagement", projectManagement);
        return prefix + "/edit";
    }

    /**
     * 修改保存专题管理
     */
    @RequiresPermissions("course:project:edit")
    @Log(title = "专题管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ProjectManagement projectManagement)
    {
        return toAjax(projectManagementService.updateProjectManagement(projectManagement));
    }

    /**
     * 删除专题管理
     */
    @RequiresPermissions("course:project:remove")
    @Log(title = "专题管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(projectManagementService.deleteProjectManagementByIds(ids));
    }
}
